import http from '../../utils/request'
const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        objectDetail:{},
        items:[],
        items1:[],
        current: 0,
        list: [{
            name: '目录'
        }, {
            name: '简介'
        }],
        scrollxItems:[],
        itemnameTitle:'',
        specId:''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let id = options.id
        let name = options.title.replace(/<br\s*\/?>/g, "")
        this.setData({itemnameTitle:name,specId:options.id})
        wx.setNavigationBarTitle({
        　　title:name
        })
        this.specialDetail(id)
        // this.specialDetail(81)
        this.getSpecialRecomment(id)
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
         // 获取加载的页面对象
         const pages = getCurrentPages();
         // 获取当前页面的对象
         const currentPage = pages[pages.length - 1];
         console.info(currentPage)
         let url= currentPage.route
       let  allurl = url+'?title='+currentPage.options.title+'&id='+currentPage.options.id
         return {
           path:allurl
         }
    },
    async specialDetail(id){
        let that = this
        var options={
           url:'/getResourcebundleById',
           method:'POST',
           data:{resourcebundleId:id},
            header:{"content-type":"application/json;charset=UTF-8"}
        }
        let res = await http(options)
        let rbmaplist=[]
        if(res.data.code==0){
            for(let key in res.data.obj.rbMap){
                rbmaplist.push({
                    name:key,
                    resoucelist:res.data.obj.rbMap[key]
                })
            }
            that.setData({objectDetail:res.data.obj.resourceBundle,items1:res.data.obj.resultItemCase3s,items:rbmaplist})
        }
    },
    change(e){
        let index = e.currentTarget.dataset.index
        this.setData({current:index})
    },
    resoucelist(e){
        let id = e.currentTarget.dataset.id
        let name = e.currentTarget.dataset.name
        wx.navigateTo({
        url: '/pages/resoucedetail/resoucedetail?id='+id+'&title='+name,
        })
    },
    //相关推荐
    async getSpecialRecomment(id){
        let that = this
        var options={
           url:'/getRecommendResourcebundlesById',
           method:'POST',
           data:{resourcebundleId:id,page:1,pagesize:10},
           header:{"content-type":"application/json;charset=UTF-8"}
        }
        let res = await http(options)
        if(res.data.code==0){
            res.data.obj.resultUitypes.map(item=>{item.neRbname = item.itemname.replace(/\<br>/g,"")})
            that.setData({scrollxItems:res.data.obj.resultUitypes})
        }
    },
    linkRouter(e){
        let title=e.currentTarget.dataset.name
        let id = e.currentTarget.dataset.id
        wx.navigateTo({
            url: `/pages/specialdetail/specialdetail?title=${title}&id=${id}`
        });
    }
})